package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduRatingLikeMapper;
import com.zenith.edu.po.domain.EduRatingLike;
import com.zenith.edu.po.dto.EduRatingLikeDTO;
import com.zenith.edu.po.vo.EduRatingLikeVO;
import com.zenith.edu.service.EduRatingLikeService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduRatingLikeServiceImpl extends ServiceImpl<EduRatingLikeMapper, EduRatingLike> implements EduRatingLikeService {
    
    @Override
    public EduRatingLikeVO createRatingLike(EduRatingLikeDTO dto) {
        EduRatingLike ratingLike = new EduRatingLike();
        BeanUtils.copyProperties(dto, ratingLike);
        this.save(ratingLike);
        
        EduRatingLikeVO vo = new EduRatingLikeVO();
        BeanUtils.copyProperties(ratingLike, vo);
        return vo;
    }
    
    @Override
    public EduRatingLikeVO getRatingLikeById(Long id) {
        EduRatingLike ratingLike = this.getById(id);
        if (ratingLike == null) {
            return null;
        }
        
        EduRatingLikeVO vo = new EduRatingLikeVO();
        BeanUtils.copyProperties(ratingLike, vo);
        return vo;
    }
    
    @Override
    public EduRatingLikeVO updateRatingLike(EduRatingLikeDTO dto) {
        EduRatingLike ratingLike = new EduRatingLike();
        BeanUtils.copyProperties(dto, ratingLike);
        this.updateById(ratingLike);
        
        EduRatingLikeVO vo = new EduRatingLikeVO();
        BeanUtils.copyProperties(ratingLike, vo);
        return vo;
    }
    
    @Override
    public boolean deleteRatingLike(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduRatingLikeVO> getRatingLikeList() {
        List<EduRatingLike> ratingLikeList = this.list();
        return ratingLikeList.stream().map(ratingLike -> {
            EduRatingLikeVO vo = new EduRatingLikeVO();
            BeanUtils.copyProperties(ratingLike, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}